package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.AdminService;
import com.qf.service.impl.AdminServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/admin")
public class AdminCotroller extends BaseServlet{
    public  String login(HttpServletRequest request, HttpServletResponse response){
        String username= request.getParameter("username");
        String password = request.getParameter("password");
        if(username==null||password==null){
            return "redirct:"+request.getContextPath()+"/admin/login.jsp";
        }
        AdminService adminService=new AdminServiceImpl();
        User user=adminService.login(username,password);
        if(user!=null){
            request.getSession().setAttribute("admin",user);
            return "redirect:"+request.getContextPath()+"/admin/admin.jsp";
        }else{
            return "redirct:"+request.getContextPath()+"/admin/login.jsp";
        }
    }
}
